import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/iconfont/iconfont.css'
import './assets/css/global.css'
import TreeTable from 'vue-table-with-tree-grid'
import dayjs from 'dayjs'


//防抖函数 (debounce),用于解决 ResizeObserver 循环警告问题
const debounce = (fn, delay) => {
  let timer
  return (...args) => {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn(...args)
    }, delay)
  }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback) {
    callback = debounce(callback, 200);
    super(callback);
  }
}

axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1/"     //拦截器   请求头
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem("token")
  return config
})


const app = createApp(App);
// app.use(TreeTable)
app.component('tree-table', TreeTable)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)      //图标引入
}

app.config.globalProperties.$axios = axios;     // 配置全局 axios
app.config.globalProperties.$dayjs = dayjs      // 配置全局 dayjs
app.use(ElementPlus);
app.use(router);
app.mount('#app');




